package ncsutest.monitors;
import ncsutest.NCSUTestController;
import ncsutest.NCSUTestMonitor;
import ncsutest.util.LEDs;

import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import com.sun.spot.sensorboard.peripheral.LEDColor;
import com.sun.spot.testFramework.ITestCases;
import com.sun.spot.testFramework.ITestResultLog;
import com.sun.spot.util.Utils;

public class LEDTestMonitor2 extends NCSUTestMonitor {
	private boolean failure;
	private ITriColorLED[] leds = EDemoBoard.getInstance().getLEDs();
	
	public LEDTestMonitor2(ITestResultLog sublog) {
		super(sublog);
	}
	
	public void setTestCases(ITestCases tests) {
		super.setTestCases(tests);
		failure = false;
	}

	public void reportSuccess(int testNo) {
		int index = testNumberToIndex(testNo);
		if (!failure) LEDs.progessBar(0, 8, (float)(index+1)/(float)getNumTests(), 0, 100, 0);
		else		  LEDs.progessBar(0, 8, (float)(index+1)/(float)getNumTests(), 100, 0, 0);

		super.reportSuccess(testNo);
	}

	public void reportError(int testNo) {
		/*int index = testNumberToIndex(testNo);
		if (!failure) {
			failure = true;
			LEDs.displayBinaryNumber(LEDColor.YELLOW, index+1, 7);
		}

		super.reportError(testNo);*/
		
		// Blow up massively
		NCSUTestController.unexpectedErrorOccured();
	}

	public void reportFailure(int testNumber, String exceptionMessage) {
		int index = testNumberToIndex(testNumber);
		failure = true;
		LEDs.progessBar(0, 8, (float)(index+1)/(float)getNumTests(), 100, 0, 0);
		
		super.reportFailure(testNumber, exceptionMessage);
	}
}
